<?php

class SystemAction extends Action{
	
	
	function Store(){
		
		$ob = M()->table("dbo.bd_ShopSet");
		
		$list = $ob->where()->select();
		
		echo Encode($list);
	}
	
	function OrderPaySuccess(){
		
		
		$orderNo = $_POST['order_no'];
		$data['out_trade_no'] = $orderNo;
		$data['cash_fee'] = $_POST['money'];
		$verify = md5($data['out_trade_no']."__meiyetong__".$data['cash_fee']);;
		
		$orderNo = substr($orderNo,0,10);
		
		if($verify == $_POST['verify']){
				
			$add = array(
					"order_no"	=> $orderNo,
					"bank"		=> $_POST['payBank'],
					"card_no"	=> $_POST['card_no'],
					"money"		=> $_POST['money']/100,
					"ip"		=> $_POST['ip'],
					"txn_id"	=> $_POST['txn_id'],
					"user"		=> $_POST['orderNo'],
					"payType"	=> $_POST['payType'],
					"hash"		=> $_POST['hash'],
					"serialize"	=> $_POST['data'],
					"commentStr"=> $_POST['commentStr'],
			);
				
			$ob = new PaymentModel();
			$s = $ob->add($add);
			if($s){
				$oo = new OrderModel();
				$order = $oo->where(array('id'=>$add['order_no']))->find();
				if($order){
					$oo->where(array('id'=>$add['order_idno']))->setField("pay_status", "1");
					echo Encode("success");
				}else{
					echo Encode("failure");
				}
		
			}else{
				$record = $ob->where(array('hash'=>$add['hash']))->find();
				if(empty($record)){
				}
				echo Encode("failure");
			}
				
		}else{
			echo Encode("failure");
		}
	}
	
	function ProjectKind(){
		$ob = M()->table("dbo.bd_Projectkinds");
		$sql = "select *, PID 
				from bd_Projectkinds where len(ProjectKindNo) <> 3 order by ProjectKindNo";
		$list = $ob->query($sql);
		echo Encode($list);
	}
	
	function ProjectSet(){
		
		$No = $_GET['No'];
		$ob = M()->table("dbo.bd_ProjectSet");
		$sql = "select * from bd_ProjectSet where ProjectKindNo = '$No'";
		$list = $ob->query($sql);
		
		echo Encode($list);
	}
	
	function ProjectSetByCode(){
		
		$ids = $_GET['ids'];
		$nid = explode(',', $ids);
		$sql = "'nnnnnnnnnnn'";
		foreach($nid as $key=>$value){
			$tmp = str_replace("'", '', $value);
			$sql .= ",'{$tmp}'";
		}
		
		
		$ob = M()->table("dbo.bd_ProjectSet");
		$sql = "select * from bd_ProjectSet where ID in ( $sql )";
		$list = $ob->query($sql);
		
		echo Encode($list);
	}
}